package com.nd.mobile.study.view.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

import com.nd.mobile.study.R;

public class GuideDialog {
	public static final String	TAG	= "GuideDialog";

	public static AlertDialog show(Context context, int imageResourceId) {
		final AlertDialog dialog = new AlertDialog.Builder(context).create();
		try {
			dialog.show();
			dialog.getWindow().setContentView(R.layout.guide_dialog_layout);
			ImageView iv = (ImageView) dialog.getWindow().findViewById(R.id.guide_iv);
			iv.setBackgroundResource(imageResourceId);
			iv.setOnTouchListener(new OnTouchListener() {

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					closeDialog(dialog);
					return false;
				}
			});
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		}
		return dialog;
	}

	private static void closeDialog(AlertDialog loading) {
		if (loading != null && loading.isShowing()) {
			try {
				loading.cancel();
			} catch (Exception e) {
				Log.e(TAG, e.getMessage());
			}
		}
	}
}
